<?php 
	namespace core;
	use PDO;

	class DB {
		public $DB;

		function __construct() {
			$this->setDB(new PDO("mysql:host=127.0.0.1;dbname=8bitfwk",'8bitfwk','8bitfwk'));					
		}

		function setDB($DB){
			$this->DB = $DB;
		}

		function getDB(){
			return $this->DB;
		}
		
		function select($sql){
			$query = $this->getDB()->query($sql);
			if(is_object($query)) {
				$res = $query->fetchAll(PDO::FETCH_ASSOC);				
			}
			else{
				$res = $query;
			}
			return $res;
		}

		function insert($sql){			
			$res = $this->getDB()->exec($sql);			
			return ($res ? $this->getDB()->lastInsertId() : false);		
		}

		function update($sql){
			$res = $this->getDB()->exec($sql);
			return $res;
		}

		function delete($sql){
			$res = $this->getDB()->exec($sql);
			return $res;
		}

		function getErrorMsg(){
			$e = $this->getDB()->errorInfo();
			return $e[2];
		}

		function beginTransaction(){
			 $this->getDB()->beginTransaction();
		}

		function commit(){
			 $this->getDB()->commit();
		}

		function rollback(){
			 $this->getDB()->rollBack();
		}
	}	
?>